﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;

namespace LabyCLI.Commands
{
	class cmd_cd
	{
        Terminal frm = Terminal.Instance;
        ChangeAutoComplete AutoComplete = new ChangeAutoComplete();

        public void Main(List<string> args)
		{
			foreach (string arg in args)
			{
                string ExpanedArg = Environment.ExpandEnvironmentVariables(arg);

                if (Directory.Exists(ExpanedArg))
				{
					Directory.SetCurrentDirectory(ExpanedArg);

					frm.Text = Directory.GetCurrentDirectory();
                    
                    AutoComplete.SetChange(frm.GetAutoCompleteMenu());

                    Terminal.WriteLine("Current directory changed to '" + Environment.CurrentDirectory + "'.");
                    Terminal.WriteLine(string.Empty);
				}
				else
				{
					Terminal.WriteLine("Invaild directory '" + ExpanedArg + "'." + Environment.NewLine, Properties.Settings.Default.Terminal_ErrorForeColor);
				}
			}
		}

		public void Main()
		{
            Terminal.WriteLine(Directory.GetCurrentDirectory());
            Terminal.WriteLine(string.Empty);
        }
	}
}
